package com.qs.controller;

/**
 * ClassName: OrderPay
 * Package: com.qs.strategy.pay
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/12/31 - 10:23
 * @Version: v1.0
 */


import com.qs.pojo.entity.Pay;
import com.qs.response.Response;
import com.qs.service.IOrderPayService;
import com.qs.strategy.PayFactory;
import com.qs.strategy.StrategyFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 订单支付接口
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/pay")
@RequiredArgsConstructor
public class PayController {

    private final IOrderPayService orderPayService;

    /**
     * 支付接口
     * @return
     */
    @PostMapping("/common")
    public Response commonPay(@RequestBody Pay pay) {
        StrategyFactory invokeStrategy = PayFactory.getInvokeStrategy(pay.getPaymentType());
        Map<String, Object> result = invokeStrategy.pay(pay);
        return Response.success(result);
    }

    /**
     * 单笔订单查询
     */
    @PostMapping("/query")
    public Response queryOrder(@RequestParam("orderId") String orderId, HttpServletRequest request){
       boolean flag = orderPayService.queryOrder(orderId, request);
        return Response.success(flag);
    }
}
